package com.polly.esphwevent.repository;

import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author liqin@nd.com.cn
 * @version V1.0
 * @title: StringCacheDao
 * @description: TODO(用一句话描述该文件做什么)
 * @date: 2019/3/27 20:34
 */
@Repository
public class StringCacheDao<K,V>{

    @Resource
    private ValueOperations<K, V> valOps;

    public void set(K key, V value) {
        valOps.set(key, value);
    }


    public void set(K key, V value, long timeout, TimeUnit unit) {
        valOps.set(key, value, timeout, unit);
    }


    public V get(K key) {
        return valOps.get(key);
    }

    public V getAndSet(K key, V value) {
        return valOps.getAndSet(key, value);
    }

    public List<V> multiGet(Collection<K> keys) {
        return valOps.multiGet(keys);
    }

    public void delete(K key) {
        valOps.getOperations().delete(key);
    }

    public void delete(Collection<K> key) {
        valOps.getOperations().delete(key);
    }

    public RedisOperations<K, V> getOperations() {
        return valOps.getOperations();
    }

    public Boolean expire(K key, long timeout, TimeUnit unit) {
        return valOps.getOperations().expire(key, timeout, unit);
    }

    public Boolean expireAt(K key, Date date) {
        return valOps.getOperations().expireAt(key, date);
    }
}
